package com.biao.synchronized_test;

public class Test09_yield extends Thread {
    @Override
    public void run() {
        for (int i = 0; i < 100; i++) {
            if (i == 30) {
                System.out.println(Thread.currentThread().getName() + "---释放cpu资源");
                this.yield();
                // 释放一次cpu资源，但下次可能还会抢到
            }
            System.out.println(Thread.currentThread().getName());
        }
    }

    public Test09_yield(String name) {
        super(name);
    }

    public static void main(String[] args) {
        new Test09_yield("1").start();
        new Test09_yield("2").start();
    }
}
